package com.aop.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

//@Component
//@Aspect
//@Order(1)
public class TimerLogger2 {

    //环绕通知(增强)
    @Around("execution(* com.aop.service.*.*(..))")
    public Object doAround(ProceedingJoinPoint joinPoint){
        System.out.println("环绕开始2...");
        long start = System.currentTimeMillis();
        try {
            Object result = joinPoint.proceed();
            return result;
        } catch (Throwable throwable) {
            throw new RuntimeException(throwable);
        }finally {
            System.out.println("环绕结束2...");
            long end = System.currentTimeMillis();
            long cost = end - start;
            System.out.println("耗时:" + cost + "毫秒");
        }
    }
}
